﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using WeiXinWeb.Models;
using WeiXinWeb.Services;

namespace WeiXinWeb.Server
{
    public class OutportServer : PSIBaseService
    {
        /// <summary>
        /// 得到所有的出口明细列表
        /// </summary>
        /// <returns></returns>
        public List<OutConsignationDetail> GetoutportList()
        {
            var result = new List<OutConsignationDetail>();
            var sql = new StringBuilder("select * from tms_out_consignation_detail");
            Query(sql.ToString(), ready =>
            {
                var item = new OutConsignationDetail
                {
                    Id = ready.GetString(ready.GetOrdinal("id")),
                    ParentId = ready.GetString(ready.GetOrdinal("parent_id")),
                    Address = ready.GetString(ready.GetOrdinal("f_address")),
                    PlanDt = ready.GetDateTime(ready.GetOrdinal("f_plan_act_dt")),
                    CntNumber1 = ready.GetString(ready.GetOrdinal("f_cnt_num_1")),
                    CntType = ready.GetString(ready.GetOrdinal("f_cnt_type")),
                    Status = ready.GetString(ready.GetOrdinal("f_status")),
                    isweixin = (IsWXStatus)Enum.Parse(typeof(IsWXStatus), ready.GetInt32(ready.GetOrdinal("i_isweixin")).ToString())
                };
                result.Add(item);
            });

            return result;
        }

        public OutConsignationDetail GetOutportSinlg(OutConsignationDetail model)
        { 
             var result=new OutConsignationDetail();
             var sql = new StringBuilder("select * from tms_out_consignation_detail where 1=1");
             var p = CreateDbParameters();
             if (!String.IsNullOrEmpty(model.Id))
             {
                 sql.Append(" and id=@id");
                 p.AddWithValue("id", model.Id);
             }
             Query(sql.ToString(), p, ready =>
             {
                 result = new OutConsignationDetail
                 {
                     Id = ready.GetString(ready.GetOrdinal("id")),
                     ParentId = ready.GetString(ready.GetOrdinal("parent_id")),
                     BlNumber = ready.GetString(ready.GetOrdinal("f_bl_number")),
                     CntType = ready.GetString(ready.GetOrdinal("f_cnt_type")),
                     CntNumber = ready.GetString(ready.GetOrdinal("f_cnt_num")),
                     Address = ready.GetString(ready.GetOrdinal("f_address")),
                     Ton = ready.GetString(ready.GetOrdinal("f_ton")),
                     GoodsOwner = ready.GetString(ready.GetOrdinal("f_goods_owner")),
                     GoodsOwnerTel = ready.GetString(ready.GetOrdinal("f_goods_owner_tel")),
                     Memo = ready.GetString(ready.GetOrdinal("f_memo")),
                     CntOwner = ready.GetString(ready.GetOrdinal("f_cnt_owner")),
                     LoadCntMan = ready.GetString(ready.GetOrdinal("f_load_cnt_man")),
                     LoadCntManTel = ready.GetString(ready.GetOrdinal("f_load_cnt_man_tel")),
                     Goods = ready.GetString(ready.GetOrdinal("f_goods")),
                     Status = ready.GetString(ready.GetOrdinal("f_status")),
                     isweixin = (IsWXStatus)Enum.Parse(typeof(IsWXStatus), ready.GetInt32(ready.GetOrdinal("i_isweixin")).ToString())
                 };
             });

            return result;
        
        }

    }
}